package wjh.mapper;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import wjh.pojo.Department;
import wjh.pojo.Doctor;
import wjh.pojo.Patient;
import wjh.pojo.Register;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Repository
public interface RegisterMapper {

    List<Register> findByNum(@Param("records_number")String records_number,@Param("patientId") int patientId);

    List<Department> findAllDepartments();
    List<Doctor> findDoctorsByDateAndDepartment(@Param("date") String date, @Param("id") String id);


    @Update("update records set deleted=1 where id=#{id}")
    void deleteById(Integer id);


    @Insert("insert into records values (null,#{records_number},#{doctor_name},#{user_name},#{user_sex},#{user_age},#{date},null,#{status},0,#{seek},#{doctor_id},#{patient_id})")
    void addRegister(Register register);


    @Select("select * from records where id=#{id}")
    Register findRecordsById(Integer id);


    @Select("SELECT * FROM records WHERE id = #{id}")
    Register findById(Integer id);
    @Update("UPDATE records SET status = #{status} WHERE id = #{id}")
    int updateStatus(@Param("id") Integer id, @Param("status") String status);


    @Select("SELECT id FROM doctor WHERE name = #{doctorName}")
    Integer getDoctorIdByName(@Param("doctorName") String doctorName);

    @Update("update plan set number=number-1 where doctor_id=#{doctorId}")
    void LessPlanNumber(@Param("doctorId") Integer doctorId);

    @Select("select * from patient where id=#{id}")
    Patient findPatientById(int id);

    @Select("select * from doctor where id=#{id}")
    Doctor findDoctorById(Integer id);


    List<Register> doctorFindAll(@Param("doctor_id") int doctor_id, @Param("user_name") String user_name, @Param("records_number") String records_number);


    void fillRecord(@Param("orders") String orders,@Param("id") int id);


    List<Register> findAllRecords(@Param("user_name")String user_name);

    @Select("select register_fee from doctor where name=#{doctorId}")
    int getRegistrationFee(String doctorId);

    @Insert("insert into records_orders values (records_number=#{recordsNumber},money=#{registerFee})")
    void addRegisterFee(@Param("recordsNumber") String recordsNumber, @Param("registerFee") Integer registerFee);


    @Delete("delete from records where id=#{id}")
    void cancelRegisters(@Param("id") String id);

    @Update("update plan set number = number - 1 WHERE doctor_id = #{doctorId} AND week = #{dayOfWeek}")
    void decrementPlanNumber(@Param("doctorId") Integer doctorId, @Param("dayOfWeek") String dayOfWeek);

}
